package com.class05.config;

import com.class05.interceptor.MyInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


@Configuration
public class MVCConfig {

    @Bean   //添加拦截器到Spring容器中
    public WebMvcConfigurer webMvcConfigurer() {
        return new WebMvcConfigurer() {
            @Override
            public void addInterceptors(InterceptorRegistry registry) {
//                addPathPatterns() 添加拦截路径
                registry.addInterceptor(new MyInterceptor()).addPathPatterns("/**");
            }
        };
    }
}
